package view;
import java.awt.Color;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;

import javax.swing.JButton;
import javax.swing.JLabel;

import javax.swing.BorderFactory;
import javax.swing.JCheckBox;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSeparator;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import net.miginfocom.swing.MigLayout;
/**
 * This class manages the Edit Meeting view window
 *
 * The Edit meeting view displays text field and areas for a meeting and allows the user to enter
 * new values to them. 
 * 
 * @author buthainahaldosary
 * @since June 1,2013
 * @version $Revision: 1.0 $
 */

public class EditMeetingView {

			
			/**
			 * Editable text field/areas for a meeting. Jpanel main container
			 */
			private JTextField topic, location, startDate,endDate, attendees;
			private JTextArea description,newDesc;
			private JPanel jPanel;
			/**
			 * Save/ send buttons and move buttons
			 */
			private JButton commitBtn,cancelBtn,deleteBtn,saveBtn,moveTopic,moveLocation,moveStart,moveEnd,moveAttendees,moveDesc,moveAll;
			/**
			 * updated fields label
			 */
			private JLabel updatedFields,previewFields;
			/**
			 * remove self from attendee list check box
			 */
			private JCheckBox removeSelf;
			/**
			 * New jtext fields
			 */
			private JTextField newTopic,newLocation,newStart,newEnd,newAttendees;
			/**
			 * Date format to be used for displaying the date.
			 */
			private String dateFormat;
			
			/**
			 * Constructor that sets the date format and calls setup components.
			 */
			public EditMeetingView() {
				dateFormat = "yyyy.MMMMM.dd hh:mm aaa";
				setupComponents();
			}
			
			/**
			 * Methods that sets up the view by initializing the fields.
			 */
			private void setupComponents() {
				startDate = new JTextField();
				endDate = new JTextField();
				topic = new JTextField();
				location = new JTextField();
				attendees = new JTextField();
				description = new JTextArea();
				deleteBtn= new JButton("Delete", IconsManager.getImageIcon("small/cross.png"));
				commitBtn = new JButton("Commit", IconsManager.getImageIcon("small/tick.png"));
				cancelBtn = new JButton("Cancel", IconsManager.getImageIcon("small/cross.png"));
				saveBtn = new JButton("Save", IconsManager.getImageIcon("small/tick.png"));
				
				updatedFields=new JLabel();
				previewFields=new JLabel();
				removeSelf = new JCheckBox("Remove self from attendee list");
				updatedFields.setText("Updated Fields:");
				previewFields.setText("Preview Fields:");
				
				//change these to use icons
				moveTopic=new JButton(IconsManager.getImageIcon("small/arrow-left.png"));
				moveLocation=new JButton(IconsManager.getImageIcon("small/arrow-left.png"));
				moveStart=new JButton(IconsManager.getImageIcon("small/arrow-left.png"));
				moveEnd=new JButton(IconsManager.getImageIcon("small/arrow-left.png"));
				moveAttendees=new JButton(IconsManager.getImageIcon("small/arrow-left.png"));
				moveDesc=new JButton(IconsManager.getImageIcon("small/arrow-left.png"));
				moveAll=new JButton(IconsManager.getImageIcon("small/arrow-double-left.png"));
				
				//temp data
				newTopic=new JTextField("new topic");
				newLocation=new JTextField("new location");
				newStart=new JTextField("new start");
				newEnd=new JTextField("new end");
				newAttendees=new JTextField("new attendees");
				newDesc=new JTextArea("new description");
				
				

			}
			
			/**
			 * Creates a JOption Pane with the components and displays it.
			 */
			public void showDialog(){
				startDate.setEditable(true);
				endDate.setEditable(true);
				topic.setEditable(false);
				location.setEditable(true);
				attendees.setEditable(true);
				description.setEditable(true);
				
				newStart.setEditable(false);
				newEnd.setEditable(false);
				newTopic.setEditable(false);
				newLocation.setEditable(false);
				newAttendees.setEditable(false);
				newDesc.setEditable(false);
				
				
				jPanel= new JPanel(new MigLayout("fillx, width 400:1000:1200"));
				JPanel details = new JPanel(new MigLayout("fillx, width 400!"));
				JPanel updates = new JPanel(new MigLayout("fillx, width 400!"));
				
				details.setBorder(BorderFactory.createMatteBorder(1, 1, 1, 1, Color.LIGHT_GRAY));
				updates.setBorder(BorderFactory.createMatteBorder(1, 1, 1, 1, Color.LIGHT_GRAY));
				
				JScrollPane descriptionScroll = new JScrollPane(description);
				JScrollPane descriptionScroll2 = new JScrollPane(newDesc);
				JSeparator separator = new JSeparator();
				JSeparator separator2 = new JSeparator();
				separator.setVisible(false);
				separator2.setVisible(false);
				//details panel
				details.add(previewFields,"wrap");
				details.add(new JLabel("Topic:"));
				details.add(topic, "wrap,growx");
				details.add(new JLabel("Location:"));
				details.add(location, "wrap, growx");
				details.add(new JLabel("Start Date:"));
				details.add(startDate, "wrap,growx");
				details.add(new JLabel("End Date:"));
				details.add(endDate, "wrap,growx");
				details.add(new JLabel("Attendees:"));
				details.add(attendees, "wrap, growx");
				details.add(descriptionScroll, "wrap,span 2, growx, h 50:200:400");
				details.add(removeSelf);
				details.add(separator, "growx, wrap");
				details.add(separator2, "growx, wrap");
				
				
				
				//updates panel
				updates.add(updatedFields,"wrap");
				updates.add(moveTopic);
				updates.add(newTopic,"wrap, growx");
				updates.add(moveLocation);
				updates.add(newLocation,"wrap,growx");
				updates.add(moveStart);
				updates.add(newStart,"wrap,growx");
				updates.add(moveEnd);
				updates.add(newEnd,"wrap,growx");
				updates.add(moveAttendees);
				updates.add(newAttendees,"wrap,growx");
				updates.add(moveDesc);
				updates.add(descriptionScroll2, "wrap,span 2, growx, h 50:200:400");
				updates.add(moveAll);
				jPanel.add(details,"growx");
				jPanel.add(updates,"growx, wrap,width 100%");
				JPanel buttonsPanel = new JPanel(new MigLayout("fillx, width 400!"));
				buttonsPanel.setBorder(BorderFactory.createMatteBorder(1, 1, 1, 1, Color.LIGHT_GRAY));
				buttonsPanel.add(saveBtn,"push, align right");
				buttonsPanel.add(deleteBtn, " align right");
				buttonsPanel.add(commitBtn, " align right");
				buttonsPanel.add(cancelBtn, "align right");

				jPanel.add(buttonsPanel, "align center,width 100%");
			
				ViewHelpers.showDialog(jPanel, "Edit Meeting");
				
			
			}
			
			/**
			 * 
			
			 * @return the topic as text. */
			public String getTopicText() {
				return topic.getText();
			}
			/**
			 * 
			
			 * @return the location as text. */
			public String getLocationText()
			{
			return location.getText();
			}
			/**
			 * 
			
			 * @return the start date as text */
			public String getStartDateText() {
				return startDate.getText();
			}
			/**
			 * 
			
			 * @return the end date as text */
			public String getEndDateText() {
				return endDate.getText();
			}
			/**
			 * 
			
			 * @return the attendees text. */
			public String getAttendeesText() {
				return attendees.getText();
			}
			/**
			 * 
			
			 * @return the description text */
			public String getDescriptionText() {
				return description.getText();
			}
			/**
			 * 
			
			 * @return the edit button */
			public JButton getCommitBtn() {
				return commitBtn;
			}
			
			/**
			 * 
			 * @param topic text to be set
			 */
			public void setTopic(String topic)
			{
				this.topic.setText(topic);
			}
			/**
			 * 
			 * @param location text to be set
			 */
			public void setLocation(String location)
			{
				this.location.setText(location);
			}
			/**
			 * 
			 * @param startDate text to be set
			 */
			public void setStartDate(String startDate)
			{
				this.startDate.setText(startDate);
			}
			/**
			 * 
			 * @param ts timestamp's text to be set
			 */
			public void setStartDate(Timestamp ts)
			{	String d = new SimpleDateFormat(dateFormat).format(ts);
				this.startDate.setText(d);
			}
			
			/**
			 * 
			 * @param ts timestamp's text to be set
			 */
			public void setEndDate(Timestamp ts)
			{	String d = new SimpleDateFormat(dateFormat).format(ts);
				this.endDate.setText(d);
			}
			/**
			 * 
			 * @param endDate text to be set
			 */
			public void setEndDate(String endDate)
			{
				this.endDate.setText(endDate);
			}
			/**
			 * 
			 * @param attendees text to be set
			 */
			public void setAttendees(String attendees)
			{
				this.attendees.setText(attendees);
			}
			/**
			 * 
			 * @param description text to be set
			 */
			public void setDescription(String description)
			{
				this.description.setText(description);
			}

			/**
			 * 
			
			 * @return the topic JTextField */
			public JTextField getTopic() {
				return topic;
			}

			/**
			 * 
			
			 * @return the location JTextField */
			public JTextField getLocation() {
				return location;
			}
			
			/**
			 * 
			
			 * @return the start date JTextField */
			public JTextField getStartDate() {
				return startDate;
			}

			/**
			 * 
			
			 * @return the end date JText field */
			public JTextField getEndDate() {
				return endDate;
			}

			/**
			 * 
			
			 * @return the attendees JText Field  */
			public JTextField getAttendees() {
				return attendees;
			}
			
			/**
			 * 
			
			 * @return the description JText field */
			public JTextArea getDescription() {
				return description;
			}

			/**
			 * 
			
			 * @return date format text */
			public String getDateFormat() {
				return dateFormat;
			}
			/**
			 * 
			
			 * @return the jpanel main controller */
			
			public JPanel getPanel()
			{
				return jPanel;
			}

			/**
			 * 
			 * @param cancelBtn JButton for cancel operation
			 */
			public void setCancelBtn(JButton cancelBtn) {
				this.cancelBtn = cancelBtn;
			}
			
			/**
			 * 
			
			 * @return the cancel JButton */
			public JButton getCancelBtn()
			{
				return cancelBtn;
			}
			/**
			 * 
			 * @return JButton for save operation
			 */
			public JButton getSaveBtn() {
				return saveBtn;
			}
			
	}


